package com.xiaowei.gym.gymjsp.ware.dao.impl;

import com.xiaowei.gym.gymjsp.ware.dao.GymMenuDao;
import com.xiaowei.gym.gymjsp.ware.dao.UserDao;
import com.xiaowei.gym.gymjsp.ware.entity.GymMenuEntity;
import com.xiaowei.gym.gymjsp.ware.util.JdbcUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class GymMenuDaoImpl implements GymMenuDao {


    @Override
    public List<GymMenuEntity> getAllMenus() {
        String sql = "SELECT * FROM gym_menu";
        List<GymMenuEntity> gymMenuEntities=null;
        try {
             gymMenuEntities = JdbcUtil.executeQuery(sql, rs -> {
                List<GymMenuEntity> menus = new ArrayList<>();
                while (rs.next()) {
                    GymMenuEntity gymMenuEntity = new GymMenuEntity();
                    gymMenuEntity.setId(rs.getInt("id"));
                    gymMenuEntity.setName(rs.getString("name"));
                    gymMenuEntity.setUrl(rs.getString("url"));
                    gymMenuEntity.setParentId(rs.getInt("parent_id"));
                    menus.add(gymMenuEntity);
                }
                return menus;
            }, null);
            System.out.println("resulSet"+gymMenuEntities);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return gymMenuEntities;
    }

    @Override
    public GymMenuEntity getMenuById(int id) {
        return null;
    }

    @Override
    public void addMenu(GymMenuEntity menu) {

    }

    @Override
    public void updateMenu(GymMenuEntity menu) {

    }

    @Override
    public void deleteMenu(int id) {

    }
}
